package com.sun.androidexerciseproject.widget.activity.ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.TextView;
import android.widget.Toast;
import com.sun.androidexerciseproject.widget.util.LogUtil;

public class WebViewActivity extends Activity {

    private WebView contentWebView = null;
    private TextView msgView = null;
    public static final String URL = "HTTPS://QR.ALIPAY.COM/FKX041645NMHML3GF3QNBC";

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contentWebView = new WebView(this);
        // 启用javascript
        contentWebView.getSettings().setJavaScriptEnabled(true);
        // 从assets目录下面的加载html
//        contentWebView.loadUrl("file:///android_asset/wst.html");
        contentWebView.loadUrl(URL);

        contentWebView.addJavascriptInterface(this, "wst");
        setContentView(contentWebView);
    }

    @JavascriptInterface
    public void startFunction() {
        Toast.makeText(this, "js调用了java函数", Toast.LENGTH_SHORT).show();
        LogUtil.log("startFunction");

    }

    @JavascriptInterface
    public void startFunction(final String str) {
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
        LogUtil.log("startFunction str = " + str);

    }
}
